package com.guandata.cdc.model.sink;

import lombok.ToString;
import org.apache.flink.api.java.utils.ParameterTool;

@ToString
public class AbstractSinkConfig {
    private static final String DEFAULT_SINK_NAME = "biz-data-sink";

    public final String sinkUsername;

    public final String sinkPassword;

    public final String sinkDatabaseName;

    public final int sinkPort;

    public final String sinkHostName;

    public final String sinkName;

    public final SinkTableNameStrategyMode sinkTableNameStrategyMode;

    public final ParameterTool parameterTool;

    public AbstractSinkConfig(ParameterTool parameterTool) {
        this.parameterTool = parameterTool;
        this.sinkDatabaseName = parameterTool.getRequired("sink.database");
        this.sinkUsername = parameterTool.getRequired("sink.username");
        this.sinkPassword = parameterTool.getRequired("sink.password");
        this.sinkPort = parameterTool.getInt("sink.port");
        this.sinkHostName = parameterTool.getRequired("sink.hostname");
        this.sinkName = parameterTool.get("sink.name", DEFAULT_SINK_NAME);
        this.sinkTableNameStrategyMode = SinkTableNameStrategyMode
                .fromCode(parameterTool.get("sink.table-name-strategy"));
    }
}
